<?php

namespace backend\models;

use Yii;

/**
 * This is the model class for table "{{%patch}}".
 *
 * @property int $id
 * @property string $title
 * @property string|null $detail
 * @property string|null $created_at
 * @property string|null $updated_at
 *
 * @property Svn[] $svns
 * @property TicketPatch[] $ticketPatches
 */
class Patch extends Base
{
    public ?int $ticket_id = null; // 这里不给预设值会报错的

    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return '{{%patch}}';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['ticket_id'], 'required'],
            [['code'], 'integer'],
            [['detail'], 'string'],
            [['created_at', 'updated_at'], 'safe'],
            [['title'], 'string', 'max' => 255],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'code' => 'Code',
            'ticket_id' => 'Ticket ID',
            'title' => 'Title',
            'detail' => 'Detail',
            'created_at' => 'Create Time',
            'updated_at' => 'Update Time',
        ];
    }

    /**
     * Gets query for [[Svns]].
     *
     * @return \yii\db\ActiveQuery
     */
    public function getSvns()
    {
        return $this->hasMany(Svn::class, ['patch_id' => 'id']);
    }

    /**
     * Gets query for [[TicketPatches]].
     *
     * @return \yii\db\ActiveQuery
     */
    public function getTicketPatches()
    {
        return $this->hasMany(TicketPatch::class, ['patch_id' => 'id']);
    }
}
